<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
 *
 * Smarty {dish_type_4} function plugin
 * @param array|null $params
 * @param Smarty $smarty
 */
function smarty_function_dish_type_4($params, $smarty) {
    if (!isset($params)) {
        return ;
    }

    if (isset($params['limit'])) {
        $limit = $params['limit'];
    } else {
        $limit = 4;
    }

    $filters = $params['filters'];
    $filters['limit'] = $limit;
    $filters['page'] = $params['page'];

    $smarty->CI->load->model('dish/dish_model');
    $data = $smarty->CI->dish_model->get_dishs($filters);
    
    if (!$data) {
        return '';
    }

    $base_url = base_url();

    $html = '';
    foreach ($data as $item) {
        $html .= "<div class='box' itemscope itemtype=\"http://schema.org/Recipe\">
                    <a href=\"{$item['link']}\" title=\"{$item['title']}\" itemprop=\"url\">
                    
                    <img src=\"{$base_url}{$item['image1']}\" alt=\"{$item['title']}\" title=\"{$item['title']}\" itemprop=\"image\"/>
                    <span class='caption fade-caption' style='position:absolute;top:0'>
                        <h2 itemprop=\"name\">{$item['title']}</h2>
                        <hr/>
                        <p itemprop=\"description\">
                            {$item['introtext']}
                        </p>
                        <div class='enclose'>
                            <img src='{$base_url}images/icon/MetroUI-Other-Search-icon.png' alt='icon-find' style='width:64px;margin:0 auto;'/>
                        </div>
                    </span>
                    </a>
                </div>";
    }
    return $html;
}
